﻿function CapsLK(e) {
    if (e.value != "")
        e.value = e.value.toUpperCase();
}
$(document).ready(function () {
    $(".inputtext").mouseenter(function () {
        if ($(this).context.className != "inputtext_focus") {
            $(this).removeClass();
            $(this).addClass("inputtext_hover");
        }
    });
    $(".inputtext").mouseleave(function () {
        if ($(this).context.className != "inputtext_focus") {
            $(this).removeClass();
            $(this).addClass("inputtext");
        }
    });
    $(".inputtext").focus(function () {
        $(this).removeClass();
        $(this).addClass("inputtext_focus");
    });
    $(".inputtext").focusout(function () {
        $(this).removeClass();
        $(this).addClass("inputtext");
    });

    $(".inputbutton").mouseenter(function () {
        if ($(this).context.className != "inputbutton_hover") {
            $(this).removeClass();
            $(this).addClass("inputbutton_hover");
        }
    });
    $(".inputbutton").mouseleave(function () {
        if ($(this).context.className != "inputbutton") {
            $(this).removeClass();
            $(this).addClass("inputbutton");
        }
    });
    $("select").change(function () {
        $(this).parent("div").find('input').val($(this).find("option:selected").text());
    });
    $("select").each(function () {
        $(this).parent("div").find('input').val($(this).find("option:selected").text());
    });
});

function ValidNull() {
    if (arguments[0] == "") {
        alert(arguments[1] + "为必填信息！");
        return false;
    }
    return true;
}

//是否为数字
function IfNumeric(e) {
    var len = e.value.length;
    for (var i = 0; i < len; i++) {
        if ((!e.value.match(/^[\+\-]?\d*?\.?\d*?$/))) {
            e.value = e.value.substr(0, e.value.length - 1);
        }
    }
    if (len == e.value.length)
        return true;
    else {
        alert('请输入数字！');
        return false;
    }
}


//+--------------------------------------------------- 
//| 求两个时间的天数差 日期格式为 YYYY-MM-dd   
//+--------------------------------------------------- 
function daysBetween(DateTwo, DateOne) {
    var OneMonth = DateOne.substring(5, DateOne.lastIndexOf('-'));
    var OneDay = DateOne.substring(DateOne.length, DateOne.lastIndexOf('-') + 1);
    var OneYear = DateOne.substring(0, DateOne.indexOf('-'));
    var TwoMonth = DateTwo.substring(5, DateTwo.lastIndexOf('-'));
    var TwoDay = DateTwo.substring(DateTwo.length, DateTwo.lastIndexOf('-') + 1);
    var TwoYear = DateTwo.substring(0, DateTwo.indexOf('-'));
    var cha = ((Date.parse(OneMonth + '/' + OneDay + '/' + OneYear) - Date.parse(TwoMonth + '/' + TwoDay + '/' + TwoYear)) / 86400000);
//    return Math.abs(cha);
    return cha;
}
//+--------------------------------------------------- 
//| 比较日期差 dtEnd 格式为日期型或者 有效日期格式字符串 
//+------------------- -------------------------------- 
function datediff(strInterval, dtStart) {

    var dtEnd = new Date();
    if (typeof dtStart == 'string')//如果是字符串转换为日期型 
    {
        dtStart = StringToDate(dtStart);
    }
    switch (strInterval) {
        case 's': return parseInt((dtEnd - dtStart) / 1000);
        case 'n': return parseInt((dtEnd - dtStart) / 60000);
        case 'h': return parseInt((dtEnd - dtStart) / 3600000);
        case 'd': return parseInt((dtEnd - dtStart) / 86400000);
        case 'w': return parseInt((dtEnd - dtStart) / (86400000 * 7));
        case 'm': return (dtEnd.getMonth() + 1) + ((dtEnd.getFullYear() - dtStart.getFullYear()) * 12) - (dtStart.getMonth() + 1);
        case 'y': return dtEnd.getFullYear() - dtStart.getFullYear();
        case 'd-h': return parseFloat((dtEnd - dtStart) / 86400000).toFixed(2);
    }
}
//+--------------------------------------------------- 
//| 比较日期差 dtStart dtEnd 格式为日期型或者 有效日期格式字符串 
//+------------------- -------------------------------- 
function dateStartEnd(strInterval, dtStart, dtEnd) {
    if (typeof dtStart == 'string')//如果是字符串转换为日期型 
    {
        dtStart = StringToDate(dtStart);
    }
    if (typeof dtEnd == 'string')//如果是字符串转换为日期型 
    {
        dtEnd = StringToDate(dtEnd);
    }
    switch (strInterval) {
        case 's': return parseInt((dtEnd - dtStart) / 1000);
        case 'n': return parseInt((dtEnd - dtStart) / 60000);
        case 'h': return parseInt((dtEnd - dtStart) / 3600000);
        case 'd': return parseInt((dtEnd - dtStart) / 86400000);
        case 'w': return parseInt((dtEnd - dtStart) / (86400000 * 7));
        case 'm': return (dtEnd.getMonth() + 1) + ((dtEnd.getFullYear() - dtStart.getFullYear()) * 12) - (dtStart.getMonth() + 1);
        case 'y': return dtEnd.getFullYear() - dtStart.getFullYear();
        case 'd-h': return parseFloat((dtEnd - dtStart) / 86400000).toFixed(2);
    }
}
//+--------------------------------------------------- 
//| 字符串转成日期类型   
//| 格式 YYYY-MM-dd-HH-mm-ss
//+--------------------------------------------------- 
function StringToDate(DateStr) {
    var converted = Date.parse(DateStr);
    var myDate = new Date(converted);
    if (isNaN(myDate)) {
        var arys = DateStr.split('-');
        myDate = new Date(arys[0], --arys[1], arys[2], arys[3], arys[4], arys[5]);
    }
    return myDate;
}
//+--------------------------------------------------- 
//| 字符串转成日期类型   
//| 格式 YYYY-MM-dd-HH-mm-ss
//+--------------------------------------------------- 
Number.prototype.pad2 = function () {
    return this > 9 ? this : '0' + this;
}      
Date.prototype.format = function (format) {
    var it = new Date();
    var it = this;
    var M = it.getMonth() + 1, H = it.getHours(), m = it.getMinutes(), d = it.getDate(), s = it.getSeconds();
    var n = { 'yyyy': it.getFullYear()
                   , 'MM': M.pad2(), 'M': M
                   , 'dd': d.pad2(), 'd': d
                   , 'HH': H.pad2(), 'H': H
                   , 'mm': m.pad2(), 'm': m
                   , 'ss': s.pad2(), 's': s
    };
    return format.replace(/([a-zA-Z]+)/g, function (s, $1) { return n[$1]; });
}
function pageCancel() {
    window.opener = null;
    window.close();
}
//判断只能为数字
function CheckInt() {
    if (!(((event.keyCode < 48) && (event.keyCode > 57)) || (event.keyCode != 45))) {
        event.returnValue = false;
    }
}
//判断只能为数字和小数点，小数点后保留3位
function CheckNumbric(value) {
    //d{3}代表3位小数
    var value = value.value;
    if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 46 && event.keyCode != 45 || /\.\d{3}$/.test(value)) 
    {event.returnValue = false; }
}

//控制搜索框
function initSec(q, forq) {
//    q = $(q);
    //    for_q = $(for_q);

    q.onfocus = function() {
        forq.style.display = 'none';
        q.style.backgroundPosition = "right -17px";
    }
    q.onblur = function() {
        if (!this.value) forq.style.display = 'block';
        q.style.backgroundPosition = "right 0";
    }
    forq.onclick = function() {
        this.style.display = 'none';
        q.focus();
    }
    if (q.value!=""){
        q.focus();
    }
}
//选中行改变颜色
var prevselitem = null;
function selectx(row) {
    if (prevselitem != null) {
        prevselitem.style.backgroundColor = '#ffffff';
    }
   
    row.style.backgroundColor = '#0080ff';
    
    prevselitem = row;

}      